﻿using SolidworksDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;


namespace TestExe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

         private void button1_Click(object sender, EventArgs e)
        {
            SolidWorksHelp.Test();         
        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
            {
                MessageBox.Show("Solidworks 未打开，获取失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetFristSolidWorksRunningObject();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
            {
                MessageBox.Show("Solidworks 未打开，获取失败2222");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(SolidWorksHelp.GetSwAppPath());
        }

        private void button5_Click(object sender, EventArgs e)   //OpenSwApp
        {
            bool b = SolidWorksHelp.OpenSwApp();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
            {
                MessageBox.Show("Solidworks 未打开，获取失败22");
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            int myState;
            string a = button.Text;
            if ("窗口最大化" == a)
            {
                myState = 1;
            }
            else if ("窗口最小化" == a)

            {
                myState = 2;
            }
            else
            {
                myState = 0;
            }

            bool b = SolidWorksHelp.GetSwApp();    //第一步先获取到swapp
            if (false == b)
            {
                MessageBox.Show(@"获取失败");
                return;
            }

            TestSw.MakeWindowSate(myState);

        }

        /// <summary>
        /// 打开SW文件，STEP，X_T,IGS
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button10_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "";
            openFileDialog1.Filter = "SW文件|*.SLDASM|stp文件|*.stp;*.step|x_t文件|*.x_t|IGES文件|*.IGS|所有文件|*.*";     //设置文件过滤器
            openFileDialog1.Title = "打开文件";           //设置对话框标题          
            openFileDialog1.FilterIndex = 1;             //表示筛选默认第几个格式
            string filename = "";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                filename = openFileDialog1.FileName;      //获得选中文件的文件名
            }
            textBox1.Text = filename;
            if (filename != "")
            {
                bool b = SolidWorksHelp.OpenSwApp();
                if (false == b)
                {
                    MessageBox.Show(@"未能获取到SolidWorks。");
                }

                string result = ModelDocHelp.OpenDoc(filename);
                if (result != "")
                {
                    MessageBox.Show(result);
                }
                List<string> modelPaths = ModelDocHelp.GetAllDoc();
                textBox2.Clear();
                foreach (var item in modelPaths)
                {
                    textBox2.AppendText(Environment.NewLine + item);
                }

            }
          
        }
    }
}
